package com.wutao.panzh.admin.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.FoodClassification;
import com.panzh.myconst.ClassificationConst;
import com.wutao.panzh.service.FoodClassificationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class FoodClassificationController {

    @Reference
    private FoodClassificationService foodClassificationService;

//    sava/food/classification  classificationName
    @RequestMapping("/sava/food/classification")
    @ResponseBody
    public ResultVO savaFoodClassification(@RequestParam("classificationName") String classificationName){
        List<FoodClassification> results = foodClassificationService.getAllClassIfication();
        //这里我们对最大的分类数进行一个限制;
        if (results.size() >= ClassificationConst.MAX_CATEGORIES){
            return new ResultVO<String>(ResultVO.FAILED,ClassificationConst.MORE_THAN_CATEGORIES,ResultVO.NO_DATA);
        }
        foodClassificationService.insertSceneryClassification(classificationName);
        return new ResultVO<String>(ResultVO.FAILED,ClassificationConst.SAVING_CLASSIFICATION_INFORMATION_SUCCEEDED,ResultVO.NO_DATA);
    }

//    delete/food/classification itemId
    @RequestMapping("/delete/food/classification")
    @ResponseBody
    public ResultVO deleteFoodClassification(@RequestParam("itemId") String itemId){
        foodClassificationService.deleteSceneryClassification(itemId);
        return new ResultVO<String>(ResultVO.SUCCESS,ClassificationConst.DELETE_CLASSIFICATION_INFORMATION_SUCCEEDED,ResultVO.NO_DATA);
    }


//    get/all/food/classification
    @RequestMapping("/get/all/food/classification")
    @ResponseBody
    public ResultVO getAllFoodClassification(){
        List<FoodClassification> results = foodClassificationService.getAllClassIfication();
        return new ResultVO<List<FoodClassification>>(ResultVO.SUCCESS,ResultVO.NO_MSG,results);
    }
}
